package com.xiaoyu.lanling.feature.ontv

import android.os.Bundle
import com.xiaoyu.base.app.AppContext
import com.xiaoyu.lanling.R
import com.xiaoyu.lanling.activity.base.AppCompatToolbarActivity
import com.xiaoyu.lanling.feature.ontv.data.TVSetting
import com.xiaoyu.lanling.feature.user.model.UserExtra
import kotlinx.android.synthetic.main.activity_how_to_be_on_tv.*

class HowToBeOnTVActivity : AppCompatToolbarActivity() {
    private val requestTag = Any()
    override fun onCreateSafelyAfterAppFinishInit(savedInstanceState: Bundle?) {
        super.onCreateSafelyAfterAppFinishInit(savedInstanceState)
        setLightStatusBar()
        setContentView(R.layout.activity_how_to_be_on_tv)
        initView()
        initBind()
    }

    private fun initBind() {
        ontv_agree.isChecked = UserExtra.instance.baseSetting.showOnTV
        ontv_disagree.isChecked = UserExtra.instance.baseSetting.showOnTV.not()
        ontv_agree.setOnCheckedChangeListener { v, checked ->
            if (checked.not()) return@setOnCheckedChangeListener
            TVSetting.updateOnTVSetting(requestTag, true)
        }

        ontv_disagree.setOnCheckedChangeListener { v, checked ->
            if (checked.not()) return@setOnCheckedChangeListener
            TVSetting.updateOnTVSetting(requestTag, false)
        }
    }

    private fun initView() {
        initToolbar()
        title = AppContext.getString(R.string.ontv_title)
        val showOnTV = UserExtra.instance.baseSetting.showOnTV
        if (showOnTV) {
            ontv_agree.isChecked = true
        } else {
            ontv_disagree.isChecked = true
        }
    }
}